import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * User: 12629
 * Date: 2021/10/15
 * Time: 8:38
 * Description:
 */

public class TestDemo {


    public static void printArray(int[] array) {
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
    }


    public static void func1(int[] array) {
        array = new int[5];
    }

    public static void func2(int[] array) {
        array[0] = 188;
    }

    public static void main(String[] args) {
        int[] array = {11,2,3,4,15};
        System.out.println(array);
        int a = 0;

        int[] array2 = null;//array2这个引用  不指向任何的对象
        //System.out.println(array2[0]);
        System.out.println(array2.length);


       /* func1(array);
        System.out.println(Arrays.toString(array));//????? 00000

        System.out.println("==============");
        func2(array);
        System.out.println(Arrays.toString(array));*/

        //printArray(array);


        //int[] array2 = new int[]{11,2,3,4,15};

    }


    public static void main8(String[] args) {
        int[] array = new int[10];
        System.out.println(Arrays.toString(array));
        //Arrays.fill(array,99);
        Arrays.fill(array,3,6,99);
        System.out.println(Arrays.toString(array));
    }

    public static void main7(String[] args) {
        int[] array = {11,2,3,4,15};
        Arrays.sort(array);

        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
        System.out.println("======增强for循环======");
        for (int val : array) {
            System.out.print(val+" ");
        }
        System.out.println("======使用操作数组的工具类Arrays=====");
        String ret = Arrays.toString(array);
        System.out.println(ret);

        /*System.out.println(array[-1]);

        System.out.println(array.length);
        System.out.println(array[0]);
        System.out.println(array[1]);
        array[0] = 999;
        System.out.println(array[0]);*/

    }


    public static void main6(String[] args) {
        int a1 = 1;
        int a2 = 2;
        int a3 = 3;
        int a4 = 4;
        //..........

        int[] array = {1,2,3,4,5,6,7,8,9,10};
        double[] array2 = {1.1,2.2};

        int[] array3 = new int[10];//大小为10  默认存储的就是0

        int[] array4 = new int[]{1,2};

    }



    public static void func(int i) {
        if(i == 1) {
            return;
        }
        func(i-1);
    }

    //n! = n*(n-1)！
    public static int fac(int n) {
        if(n == 1) {
            return 1;
        }
        int tmp =  n * fac(n-1);
        return tmp;
    }
    //123
    public static void print(int n){
        if(n > 9) {
            print(n/10);
        }
        System.out.println(n%10);
    }

    public static int sum(int n) {
        if(n == 1) {
            return 1;
        }
        return n+sum(n-1);
    }

    public static int func2(int n) {
        if(n < 10) {
            return n;
        }
        return n % 10 + func2(n/10);
    }
    public static int count = 0;
    public static int  fib1(int n) {
        if(n <= 0) return 0;
        if(n == 1 || n == 2) {
            count++;
            return 1;
        }
        return fib1(n-1)+fib1(n-2);//多路递归
    }

    public static int  fib(int n) {
        if(n == 1 || n == 2) return 1;
        int f1 = 1;//1
        int f2 = 1;//2
        int f3 = 0;
        for (int i = 3; i <= n; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }

    /**
     * 1:A->C                 1
     * 2:A->B A->C  B->C            3
     * 3:A->C A->B C->B A->C B->A B->C A->C    7
     * N:   2^N  -1
     * pos1:起始位置
     * pos2:中专位置
     * pos3:目的位置
     */
    public static void hanio(int n,char pos1,char pos2,char pos3) {
        if(n == 1) {
            move(pos1,pos3);
        }else {
            hanio(n-1,pos1,pos3,pos2);
            move(pos1,pos3);
            hanio(n-1,pos2,pos1,pos3);
        }
    }

    public static void move(char pos1,char pos2) {
        System.out.print(pos1+"->"+pos2+" ");
    }

    public static void main2(String[] args) {
        hanio(64,'A','B','C');
        System.out.println();
        /*hanio(2,'A','B','C');
        System.out.println();
        hanio(3,'A','B','C');*/

        //System.out.println(fib(42));
        //System.out.println(TestDemo.count);

        //System.out.println(fac(5));
    }

    public static void main1(String[] args) {
        func(2);
    }

}
